package fr.esiag.isidis.epp.search;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fr.esiag.isidis.epp.generatedClasses.Query;
import fr.esiag.isidis.epp.generatedClasses.QueryExportCdc;
import fr.esiag.isidis.epp.service.CDCAndWeightService;

@Service
public class PointCdcService {

	private static Logger logger = Logger.getLogger(CDCAndWeightService.class);
	
	@Autowired
	private PointCdcRepository repository;
	
	public List<PointCdc> makeIndividuel(Query q){
		return repository.individualQuery(q);
	}
	
	public List<PointCdc> makeCumul(Query q){
		return repository.cumulQuery(q);
	}
	
	public List<PointCdc> makeMoyenne(Query q){
		return repository.moyenneQuery(q);
	}
	
	public List<List<PointCdc>>  traiteQuery(QueryExportCdc qec){
		List<List<PointCdc>> reponse = new ArrayList<List<PointCdc>>() ;
		List<Query> listq = qec.getQuery();
		for(Query q : listq){
			if(q.getType().equals("individuel")){
				reponse.add(makeIndividuel(q));
			}
			
			if(q.getType().equals("cumule")){
				reponse.add(makeCumul(q));
			}
			
			if(q.getType().equals("moyenne")){
				reponse.add(makeMoyenne(q));
			}
		}
		return reponse;
	}
}
